package com.lhh.algorithmservice.config;

import org.apache.spark.SparkConf;
import org.apache.spark.sql.SparkSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

/**
 * @author 李厚航
 */
@Configuration
public class SparkConfiguration {

    private final SparkConfigurationProperties sparkConfigurationProperties;

    @Autowired
    public SparkConfiguration(SparkConfigurationProperties sparkConfigurationProperties) {
        this.sparkConfigurationProperties = sparkConfigurationProperties;
    }

    @Bean
    public SparkSession sparkSession() {
        // 加载库文件
        if(sparkConfigurationProperties.getDllAnalysis()){
            System.load(sparkConfigurationProperties.getDllPath());
        }
        return SparkSession.builder()
                .appName(sparkConfigurationProperties.getAppName())
                .master(sparkConfigurationProperties.getMaster())
                .config("spark.sql.warehouse.dir", sparkConfigurationProperties.getDataPath())
                .getOrCreate();
    }

}
